package 力扣热题100;

import java.util.Arrays;

public class LeetCode15 {
    public void nextPermutation(int[] nums) {
        for (int i = nums.length-1; i >=0 ; i--) {
            for (int j = nums.length-1; j > i; j--) {
                if(nums[i]<nums[j]){
                    swap(nums,i,j);
                    Arrays.sort(nums,i+1,nums.length);
                    return;
                }
            }
        }
        Arrays.sort(nums);
    }

    private void swap(int[] nums, int i, int j) {
        int tmp=nums[i];
        nums[i]=nums[j];
        nums[j]=tmp;
    }

    public static void main(String[] args) {
        LeetCode15 leetCode15=new LeetCode15();
        leetCode15.nextPermutation(new int[]{1,3,2});
    }
}
